package com.yc.service.miniapp.Impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.yc.dao.DaoSupport;
import com.yc.entity.Page;
import com.yc.service.miniapp.AppColumnService;
import com.yc.util.PageData;

@Service("appColumnService")
public class AppColumnServiceImpl implements AppColumnService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	
	@Override
	@SuppressWarnings("unchecked")
	public List<PageData> listAllAppCoulumn(PageData pd) throws Exception {
		// TODO Auto-generated method stub
		return (List<PageData>) dao.findForList("AppColumnMapper.listcolumn", pd);
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<PageData> listAllProductbyColumnId(Page page) throws Exception{
		if(page!=null && StringUtils.isNotBlank(page.getPd().getString("COLUMN_ID"))){
			if(page.getPd().getString("COLUMN_ID").equals("0")){
				return (List<PageData>) dao.findForList("AppColumnMapper.getProductByRanke", page);
			}else{
				return (List<PageData>) dao.findForList("AppColumnMapper.getProductByColumnidlistPage", page);
			}
		}
		return (List<PageData>) dao.findForList("AppColumnMapper.getAllProductlistPage", page);
		
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<PageData> getAllProductByColumnId(Page page) throws Exception{
		if(page!=null && StringUtils.isNotBlank(page.getPd().getString("COLUMN_ID"))){
			if(page.getPd().getString("COLUMN_ID").equals("0")){
				return (List<PageData>) dao.findForList("AppColumnMapper.getProductByRanke", page);
			}else{
				return (List<PageData>) dao.findForList("AppColumnMapper.getAllProductsByColumnid", page);
			}
		}
		return (List<PageData>) dao.findForList("AppColumnMapper.getAllProducts", page);
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<PageData> testgetAllProductByColumnId(Page page) throws Exception
	{
		return (List<PageData>) dao.findForList("AppColumnMapper.getTestAllProducts", page);
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<PageData> listAllProductbyKeyWord(Page page) throws Exception
	{
		if(StringUtils.isNotBlank(page.getPd().getString("keywords"))){
			return (List<PageData>) dao.findForList("AppColumnMapper.getProductBySearchlistPage", page);
		}else{
			return null;
		}
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<PageData> getLabelByids(String[] arr) throws Exception
	{
		return (List<PageData>) dao.findForList("AppColumnMapper.getLabels", arr);
	}
}
